package s_003_Bean_Property_Value;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.Environment;
import s_003_Bean_Property_Value.bean.People;
import s_003_Bean_Property_Value.config.PropertyValuesConfig;


public class MainAnn {

    public static void main(String[] args) {
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(PropertyValuesConfig.class);

        printBeans(applicationContext);

        People person = (People) applicationContext.getBean("people");
        System.out.println(person);

        Environment environment = applicationContext.getEnvironment();
        String property = environment.getProperty("people.nickName");
        System.out.println(property);

        ((AnnotationConfigApplicationContext) applicationContext).close();
    }


    private static void printBeans(ApplicationContext applicationContext) {
        //打印IOC容器中所有bean的名称
        String[] definitionNames = applicationContext.getBeanDefinitionNames();
        for (String name : definitionNames) {
            System.out.println(name);
        }
        System.out.println("===================================");
    }
}
